package com.szy.assembly;

import java.io.Serializable;

public class Instruction implements Serializable {




    public InstructionEnum opcode;
    public int[] operand;
    public int operandNum;
    private String originalText="#";
    private String label="";

    public Instruction(InstructionEnum opcode){
        this.opcode=opcode;
        this.operand=new int[4];
        this.operandNum=0;
    }
    public Instruction(InstructionEnum opcode,int operand1){
        this.opcode=opcode;
        this.operand=new int[4];
        this.operand[0]=operand1;
        this.operandNum=1;
    }
    public Instruction(InstructionEnum opcode,int operand1,int operand2){
        this.opcode=opcode;
        this.operand=new int[4];
        this.operand[0]=operand1;
        this.operand[1]=operand2;
        this.operandNum=2;
    }
    public Instruction(InstructionEnum opcode,int operand1,int operand2,int operand3){
        this.opcode=opcode;
        this.operand=new int[4];
        this.operand[0]=operand1;
        this.operand[1]=operand2;
        this.operand[2]=operand3;
        this.operandNum=3;
    }
    public Instruction(InstructionEnum opcode,int operand1,int operand2,int operand3,int operand4){
        this.opcode=opcode;
        this.operand=new int[4];
        this.operand[0]=operand1;
        this.operand[1]=operand2;
        this.operand[2]=operand3;
        this.operand[3]=operand4;
        this.operandNum=4;
    }

    public Instruction(InstructionEnum opcode,int[] operands,int operandNum){
        this.opcode=opcode;
        this.operand=new int[4];
        if (operandNum >= 0) System.arraycopy(operands, 0, this.operand, 0, operandNum);
        this.operandNum=operandNum;
    }

    public Instruction setOriginalText(String text){
        this.originalText=text;
        return this;
    }

    public String getOriginalText(){
        return this.originalText;
    }

    void setLabel(String l){
        this.label=l;
    }

    String getLabel(){
        return this.label;
    }

}
